<%@ page language="java" contentType="text/html; charset=UTF-8" %>

<%@ page import="org.apache.commons.lang3.StringUtils,weaver.conn.RecordSet" %>
<%@ page import="weaver.general.Util"%>
<%@ page import="weaver.integration.logging.Logger"%>
<%@ page import="weaver.integration.logging.LoggerFactory" %>
<%@ page import="weaver.interfaces.HrmTransferDao" %>
<%@ include file="/systeminfo/init_wev8.jsp" %>

<%
    Logger log = LoggerFactory.getLogger();

    RecordSet rs = new RecordSet();

    String workflowId = request.getParameter("workflowid");
    String sysId = request.getParameter("sysid");
	String isMsg = Util.null2String(request.getParameter("_weaverofsmsg"));

    int userId = user.getUID() ;
    String appURL ;
    if(StringUtils.isNotBlank(workflowId)){
        //新建异构系统
        log.error("workflowid="+workflowId);
        rs.executeQuery("select * from ofs_workflow where workflowid = ?",workflowId);
        rs.next();
        appURL = rs.getString("APPCWURL");
        if ("".equals(Util.null2String(sysId))){
            sysId = rs.getString("SYSID");
        }
    }else{
        //访问异构系统流程
        String todoDataId = request.getParameter("tododataid");
        log.error("todoDataId="+todoDataId);
        String isRemark = request.getParameter("isremark");
        log.error("isRemark="+isRemark);

        if( "0".equals(isRemark) || "8".equals(isRemark)){
            rs.executeQuery("select * from ofs_todo_data where id = ?",todoDataId);
            rs.next();
            appURL =  Util.null2String(rs.getString("appurlsrc"));
            if ("".equals(Util.null2String(sysId))){
                sysId = rs.getString("SYSID");
            }
        }else{
            rs.executeQuery("select * from ofs_done_data where id = ?",todoDataId);
            rs.next();
            appURL =  Util.null2String(rs.getString("appurlsrc"));
            if ("".equals(Util.null2String(sysId))){
                sysId = rs.getString("SYSID");
            }
        }
    }

    rs.executeQuery("select * from ofs_sysinfo where sysid = ?" , sysId);
    if(rs.next()){
        String prefixURL = Util.null2String(rs.getString("Appprefixurl"));
        String hrmTransRule = Util.null2String(rs.getString("HRMTRANSRULE"));//人员转换关系

        HrmTransferDao hrmTransferDao = new HrmTransferDao();
        String loginId = hrmTransferDao.getHrmResourceIdByHrmTransRule(hrmTransRule, Util.null2String(userId));

//        String token = this.getToken(prefixURL , loginId) ;
//		if ("".equals(token)){
//			out.println("get Token is null ");
//			return ;
//		}
//		if (token.contains(":")){
//			out.println("get Token is err : " + token);
//			return ;
//		}
        String toURL = prefixURL +loginId+"&ofsComeFrom=e9";
        log.error("APP端访问异构系统地址："+toURL);
%>
<script type="text/javascript">

    location.replace('<%=toURL%>');

</script>
<%

    }else{
        log.error("根据标识："+sysId+"未查询到数据");
        return;
    }


%>
